package cn.tedu._05mvcboot02.common.exception;

import cn.tedu._05mvcboot02.common.response.JsonResult;
import cn.tedu._05mvcboot02.common.response.StatusCode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler
    public JsonResult doHandleIllegalArgumentException(IllegalArgumentException e){
        log.error("IllegalArgumentException =",e.getMessage());
        return new JsonResult(StatusCode.OPERATION_FAILED,e.getMessage());
    }

    @ExceptionHandler
    public JsonResult doHandleException(RuntimeException e){
        log.error("RuntimeException="+e.getMessage());
        return new JsonResult(StatusCode.OPERATION_FAILED, e.getMessage());
    }
    @ExceptionHandler
    public JsonResult doHandleThrowable(Throwable e){
        log.error("Throwable="+e.getMessage());
        return new JsonResult(StatusCode.THROWABLE_ERROR, e.getMessage());

    }
}
